package Chapter1.sort;

public class SelectSort {
    public static void main(String[] args) {
        int nums[] = {1, 5, 3, 2, 4};
        sort(nums);
        for (int num : nums) {
            System.out.println(num);
        }
    }

    public static void sort(int[] nums) {
        int len = nums.length;
        for (int i = 0; i < len; i++) {
            int min = nums[i];
            int minIndex = i;
            for (int j = i + 1; j < len; j++) {
                if (min > nums[j]) {
                    min = nums[j];
                    minIndex = j;
                }
            }
            int temp = nums[i];
            nums[i] = min;
            nums[minIndex] = temp;
        }
    }
}
